<template>
    <view>
        <j-cell-group>
            <template v-for="(item, index) in deviceTypePropList">
                <j-cell :key="item.id" :title="item.propName" @jftap="onBindtapControl(item)"></j-cell>
            </template>
        </j-cell-group>
    </view>
</template>

<script>
// pages/scene/condition-status-prop/condition-status-prop.js
export default {
    data() {
        return {
            device: {},
            deviceTypePropList: []
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
        console.log('=== scene:condition-status-prop:onLoad:', JSON.parse(decodeURIComponent(options.device)));
        let device = JSON.parse(decodeURIComponent(options.device));
        this.device = device
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        console.log('=== scene:condition-status-prop:onReady:');
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        console.log('=== scene:condition-status-prop:onShow:');
        this.getDeviceTypePropListByPageForApp();
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
        console.log('--- scene:condition-status-prop:onHide:');
    },
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
        console.log('--- scene:condition-status-prop:onUnload:');
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        // 分页查询设备类型属性列表
        getDeviceTypePropListByPageForApp() {
            let data = {
                pid: this.device.pid,
                isCondition: true,
                //true表示查询条件，false表示查询动作
                page: 1,
                limit: 999
            };
            getApp().globalData.api.getDeviceTypePropListByPageForApp(data, (result) => {
                console.log('设备的属性列表：', result); // let deviceTypePropList = result.data
                // for (let i = 0; i < deviceTypePropList.length; i++) {
                //     const item = deviceTypePropList[i];
                //     item.propValue = JSON.parse(item.propValue)
                // }

                this.deviceTypePropList = result.data
            });
        },

        // 点击选择具体的属性
        onBindtapControl(ev) {
            let props = ev;
            uni.navigateTo({
                url: `/jvss/pagesScene/condition-status-prop-control/condition-status-prop-control?device=${encodeURIComponent(JSON.stringify(this.device))}&props=${encodeURIComponent(JSON.stringify(props))}`
            });
        }
    }
};
</script>
<style>
/* pages/scene/condition-status-prop/condition-status-prop.wxss */
</style>
